<template>
  <div>
    <a-modal :visible="visible" @cancel="visible=false" :width="800" :footer="null" title="家长端权限">
      <a-spin :spinning="loading">
        <div class="parentConfig">
           <div class="config-list" v-if="isShowLive">
            <div class="item-config">
              <span class="title">直播课</span>
              <span class="switch">
                <a-switch v-model="value.live" @change="onChange" />
              </span>
              <span class="desc">开启后，家长端可以查看学员需要上的直播课</span>
            </div>
          </div>

          <div class="config-list">
            <div class="item-config">
              <span class="title">作业</span>
              <span class="switch">
                <a-switch v-model="value.homework" @change="onChange" />
              </span>
              <span class="desc">开启后，家长端可以查看学员的作业和提交作业内容</span>
            </div>
          </div>


          <div class="config-list">
            <div class="item-config">
              <span class="title">评价老师</span>
              <span class="switch">
                <a-switch v-model="value.evaluation_teachers" @change="onChange" />
              </span>
              <span class="desc">开启后，家长端可以在每次上课点名后为老师评分和填写评价内容</span>
            </div>
          </div>
          <div class="config-list">
            <div class="item-config">
              <span class="title">课时查询</span>
              <span class="switch">
                <a-switch v-model="value.class_hour_inquiry" @change="onChange" />
              </span>
              <span class="desc">开启后，家长端可以查看学员的所有报读课程、剩余课时、上课记录等课程记录信息</span>
            </div>
          </div>
          <div class="config-list">
            <div class="item-config">
              <span class="title">课表</span>
              <span class="switch">
                <a-switch v-model="value.timetable" @change="onChange" />
              </span>
              <span class="desc">开启后，家长端可以查看学员所有课程的上课时间、教室等信息</span>
            </div>
          </div>

          <div class="config-list">
            <div class="item-config">
              <span class="title">成绩单</span>
              <span class="switch">
                <a-switch v-model="value.exam_report" @change="onChange" />
              </span>
              <span class="desc">开启后，家长端开启“成绩单”功能，录入成绩时仍可选择不展示给家长</span>
            </div>
          </div>
          <div class="config-list">
            <div class="item-config">
              <span class="title">我的订单</span>
              <span class="switch">
                <a-switch v-model="value.my_order" @change="onChange" />
              </span>
              <span class="desc">开启后，家长端可以查看学员的所有报名收据、退转课等订单信息</span>
            </div>
          </div>
        </div>
      </a-spin>
    </a-modal>
  </div>
</template>

<script>
import { parentPowerGet, parentPowerSet } from '@/api/parentClient'
import { appCenterList } from '@/api/lives'
export default {
  name: 'parentSetting',
  data() {
    return {
      visible: false,
      loading: false,
      value: {
        class_hour_inquiry: true,
        evaluation_teachers: true,
        exam_report: true,
        my_order: true,
        live:false,
        homework:true,
        timetable:true
      },
      isShowLive:true,
      roleData:[]
    }
  },
 
  methods: {
    //判断直播是否显示
    getList() {
      // appCenterList({ school_id: this.$store.state.user.school}).then((res) => {
      //   res.forEach(item=>{
      //     if(item.key=='Live'){
      //       this.isShowLive=true
      //     }
      //     else{
      //       this.isShowLive=false
      //     }
      //   })
      // })
      
       this.roleData = this.$store.getters.roles.permissionList
       if(this.roleData.indexOf('interactClass')==-1){
          this.isShowLive=false
        console.log(this.isShowLive)
       }
       console.log(this.roleData)
    },
    showModel() {
      this.visible = true
      this.loading = true
      parentPowerGet({
        school_id: this.$store.state.user.school,
        key: 'parental_rights',
      })
        .then((res) => {
          if (res.value && !(res.value instanceof Array)) {
            this.value = res.value
          }
        })
        .catch((err) => {
          this.$message.error(err.data.message || '获取数据失败')
        })
        .finally(() => {
          this.loading = false
        })
      this.getList()
    },
    onChange() {
      this.loading = true
      parentPowerSet({
        school_id: this.$store.state.user.school,
        key: 'parental_rights',
        value: this.value,
      })
        .then((res) => {
          this.value = res.value
        })
        .catch((err) => {
          this.$message.error(err.data.message || '设置失败')
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>

<style lang="less" scoped>
.parentConfig {
  .config-list {
    .item-config {
      margin-bottom: 18px;
      span {
        display: inline-block;
      }
      .title {
        width: 100px;
      }
      .switch {
        position: relative;
        top: -2px;
      }
      .desc {
        margin-left: 8px;
        color: rgb(153, 153, 153);
        word-break: break-all;
      }
    }
  }
}
</style>